package test.serverframe.armc.server.manager.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

import test.serverframe.armc.server.manager.controller.vo.TaskHistoryVo;
import test.serverframe.armc.server.manager.dao.mapper.InvokeTaskRecordMapper;
import test.serverframe.armc.server.manager.domain.InvokeTaskRecord;
import test.serverframe.armc.server.manager.domain.params.HistoryRecordParam;
import test.serverframe.armc.server.manager.domain.params.TaskImplementParams;

import java.util.List;

/**  
* 
* @author yegui  
* @date 2018年12月11日  
*/
@Service
public class InvokeTaskRecordServiceImpl {
	
	@Autowired
	private InvokeTaskRecordMapper taskRecordMapper;
	@Autowired
	private  InvokeTaskRecordMapper invokeTaskRecordMapper;

	public void insert(InvokeTaskRecord taskRecord) {
		taskRecordMapper.insert(taskRecord);
	}
	
	public int updateByPrimaryKeySelective(InvokeTaskRecord taskRecord) {
		return taskRecordMapper.updateByPrimaryKeySelective(taskRecord);
	}

	@Transactional
	public List<TaskImplementParams> selectTaskImplement(String LastInvokeRecordId){

		return invokeTaskRecordMapper.selectTaskImplement(LastInvokeRecordId);
	}
	
	/*
	 *  获取调度历史详情中的任务名称和任务执行顺序
	 * @author yegui  
	 * @date 2018年12月14日  
	 * @param invokeRecordId
	 * @return
	 * List<TaskDefine>
	 */
	public TaskHistoryVo getTaskRecord(HistoryRecordParam params) {
		/*List<HistoryRecord> recordList = invokeTaskRecordMapper.findByInvokeRecordId(params.getRecordId());
		List<TaskHistoryVo> voList = new ArrayList<>();
		for (HistoryRecord record : recordList) {
			record.setTaskInvokeId(params.getTaskInvokeId());
			TaskHistoryVo vo = invokeTaskRecordMapper.getTaskRecord(record);
			if (vo != null) {
				vo.setTaskRecordId(record.getTaskRecordId());
				vo.setStatus(record.getStatus());
				voList.add(vo);
			}
		}
		//对voList集合用taskOrder进行排序
		TreeMap<Integer, TaskHistoryVo> map = new TreeMap<>();
		for (TaskHistoryVo vo : voList) {
			//map.put(vo.getTaskOrder(), vo);
		}
		voList.clear();
		Iterator<Integer> it = map.keySet().iterator();
		while (it.hasNext()) {
			voList.add(map.get(it.next()));
		}*/
		List<TaskHistoryVo> vos = invokeTaskRecordMapper.getTaskRecord(params);
		for (TaskHistoryVo vo : vos){
			return vo;
		}
		return null;	
	}
	
	

}
